import {Toast} from "vant";

export const ToastBox = {
    _toast: null,
    showLoading(message = '', duration = 0) {
        return new Promise(resolve => {
            this.closeLoading();
            const _toast = Toast.loading({
                duration, // 0 持续展示 toast
                forbidClick: true,
                message,
                onClose: () => {
                    this._toast = null;
                    resolve()
                }
            });
            if (duration === 0) {
                this._toast = _toast;
            }
        })


    },
    closeLoading() {
        if (this._toast) {
            if (typeof this._toast.clear === 'function') {
                this._toast.clear();
            }
            this._toast = null;
        }
    },
}
